/**
 * Project: topdt-jbpm
 * Copyright 2013  Top Digital Technology  Co. Ltd.
 * All right reserved.
 */
package com.topdt.jbpm.dao;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.SQLQuery;
import org.springframework.stereotype.Repository;

import com.thx.common.orm.HibernateBaseDao;
import com.thx.common.util.AppContext;
import com.topdt.jbpm.model.ActorDefinDetail;

/**
 * 建立日期 : 2013-4-25 下午12:02:36<br>
 * 作者 : balance<br>
 * 模块 : <br>
 * 描述 : <br>
 * 修改历史: 序号 日期 修改人 修改原因 <br>
 * 1 <br>
 * 2 <br>
 */
@Repository
public class ActorDefinDetailDao extends HibernateBaseDao<ActorDefinDetail> {

	@SuppressWarnings("unchecked")
	public List<ActorDefinDetail> findByActivityId(String activityId) {
		String comId = AppContext.getCurrentComId();
		String hql = "from ActorDefinDetail a where a.companyId = ? and a.activityId = ?";
		return createQuery(hql, new Object[]{comId, activityId}).list();
	}


	public void delByActivityId(String activityId) {
		String hql = "delete from ActorDefinDetail where activityId = ?";
		createQuery(hql, new Object[]{activityId}).executeUpdate();
	}

	public void addActorDefinDetail(String companyId) throws HibernateException{
		String sql = "insert into wf_actor_defin_detail w (w.DETAIL_ID,w.ACTOR_TYPE,w.ACTORS,w.ACTIVITY_ID,w.COMPANY_ID) " +
				" select :companyId||wf.DETAIL_ID,wf.ACTOR_TYPE,wf.ACTORS,:companyId||wf.ACTIVITY_ID,:companyId " +
				" from sys_wf_actor_defin_detail wf";
		SQLQuery sqlQ = (SQLQuery) createSqlQuery(sql).setString("companyId", companyId);
		sqlQ.executeUpdate();
	}
}
